/*
 * Copyright 2011 Angel Sanadinov
 *
 * This file is part of VBox WMI.
 *
 * VBox WMI is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * VBox WMI is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with VBox WMI.  If not, see <http://www.gnu.org/licenses/>.
 */

package Beans.Responses.DataRetrievalComponents;

import Utilities.Constants.MiscellaneousRequestType;
import com.sun.xml.ws.commons.virtualbox_3_2.IGuestOSType;
import com.sun.xml.ws.commons.virtualbox_3_2.IMediumFormat;

/**
 * This class represents a miscellaneous data component, when retrieved from the system.
 *
 * @see GuestOSTypeDataComponent
 * @see MediumFormatDataComponent
 *
 * @author Angel Sanadinov
 */
public class MiscDataComponent extends DataRetrievalComponent
{
    private MiscellaneousRequestType requestType;       //type of request
    private GuestOSTypeDataComponent[] guestOSTypes;    //array of guest os type components
    private MediumFormatDataComponent[] mediumFormats;  //array of medium format components

    /**
     * Constructs the data component using guest OS types data.
     *
     * @param guestOSTypes the guest OS types data, supplied by the VirtualBox server
     */
    public MiscDataComponent(IGuestOSType[] guestOSTypes)
    {
        if(guestOSTypes != null)
        {
            this.guestOSTypes = new GuestOSTypeDataComponent[guestOSTypes.length];
            for(int i = 0; i < guestOSTypes.length; i++)
                this.guestOSTypes[i] = new GuestOSTypeDataComponent(guestOSTypes[i]);

            this.requestType = MiscellaneousRequestType.GUEST_OS_TYPES;
        }
        else
            this.guestOSTypes = null;
    }

    /**
     * Constructs the data component using medium formats data.
     *
     * @param mediumFormats the medium formats data, supplied by the VirtualBox server
     */
    public MiscDataComponent(IMediumFormat[] mediumFormats)
    {
        if(mediumFormats != null)
        {
            this.mediumFormats = new MediumFormatDataComponent[mediumFormats.length];
            for(int i = 0; i < mediumFormats.length; i++)
                this.mediumFormats[i] = new MediumFormatDataComponent(mediumFormats[i]);

            this.requestType = MiscellaneousRequestType.MEDIUM_FORMATS;
        }
        else
            this.mediumFormats = null;
    }

    /**
     * Retrieves the guest OS types, if available.
     *
     * @return the guest OS types or <code>null</code> if this component is not
     *         returned in response to a guest OS types request
     */
    public GuestOSTypeDataComponent[] getGuestOSTypes()
    {
        return guestOSTypes;
    }

    /**
     * Retrieves the medium formats, if available.
     *
     * @return the medium formats or <code>null</code> if this component is not
     *         returned in response to a medium formats request
     */
    public MediumFormatDataComponent[] getMediumFormats()
    {
        return mediumFormats;
    }

    /**
     * Retrieves the type of the request, to which this component is returned.
     *
     * @return the request type
     */
    public MiscellaneousRequestType getRequestType()
    {
        return requestType;
    }

    @Override
    public boolean isValid()
    {
        if((requestType == MiscellaneousRequestType.GUEST_OS_TYPES && guestOSTypes != null)
                || (requestType == MiscellaneousRequestType.MEDIUM_FORMATS && mediumFormats != null))
            return true;
        else
            return false;
    }
}
